{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"http://hilpisch.com/tpq_logo.png\" alt=\"The Python Quants\" width=\"35%\" align=\"right\" border=\"0\"><br><br><br>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Listed Volatility and Variance Derivatives\n",
    "\n",
    "**Dr. Yves J. Hilpisch &mdash; Wiley Finance (2016)**\n",
    "\n",
    "<img src=\"http://hilpisch.com/images/lvvd_cover.png\" alt=\"Derivatives Analytics with Python\" width=\"30%\" align=\"left\" border=\"0\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# DX Analytics &mdash; Square-Root Diffusion "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Introduction "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You need to install DX Analytics. See http://dx-analytics.com."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Data Import and Selection"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import warnings; warnings.simplefilter('ignore')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import datetime as dt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "h5 = pd.HDFStore('data/vstoxx_march_2014.h5', 'r')\n",
    "vstoxx_index = h5['vstoxx_index']  # data for the index itself \n",
    "vstoxx_futures = h5['vstoxx_futures']  # data for the futures\n",
    "vstoxx_options = h5['vstoxx_options']  # data for the options\n",
    "h5.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "DatetimeIndex: 63 entries, 2014-01-02 to 2014-03-31\n",
      "Data columns (total 9 columns):\n",
      "V2TX    63 non-null float64\n",
      "V6I1    57 non-null float64\n",
      "V6I2    63 non-null float64\n",
      "V6I3    61 non-null float64\n",
      "V6I4    63 non-null float64\n",
      "V6I5    63 non-null float64\n",
      "V6I6    62 non-null float64\n",
      "V6I7    63 non-null float64\n",
      "V6I8    63 non-null float64\n",
      "dtypes: float64(9)\n",
      "memory usage: 4.9 KB\n"
     ]
    }
   ],
   "source": [
    "vstoxx_index.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>V2TX</th>\n",
       "      <th>V6I1</th>\n",
       "      <th>V6I2</th>\n",
       "      <th>V6I3</th>\n",
       "      <th>V6I4</th>\n",
       "      <th>V6I5</th>\n",
       "      <th>V6I6</th>\n",
       "      <th>V6I7</th>\n",
       "      <th>V6I8</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2014-03-25</th>\n",
       "      <td>18.2637</td>\n",
       "      <td>18.2303</td>\n",
       "      <td>18.3078</td>\n",
       "      <td>19.0371</td>\n",
       "      <td>19.8378</td>\n",
       "      <td>20.3065</td>\n",
       "      <td>18.1063</td>\n",
       "      <td>20.8292</td>\n",
       "      <td>21.2046</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-03-26</th>\n",
       "      <td>17.5869</td>\n",
       "      <td>17.4810</td>\n",
       "      <td>17.7009</td>\n",
       "      <td>18.4499</td>\n",
       "      <td>19.4150</td>\n",
       "      <td>19.9961</td>\n",
       "      <td>20.2562</td>\n",
       "      <td>20.4541</td>\n",
       "      <td>20.8563</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-03-27</th>\n",
       "      <td>17.6397</td>\n",
       "      <td>17.5032</td>\n",
       "      <td>17.7608</td>\n",
       "      <td>18.6249</td>\n",
       "      <td>19.4860</td>\n",
       "      <td>20.0477</td>\n",
       "      <td>20.1078</td>\n",
       "      <td>20.4865</td>\n",
       "      <td>20.9449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-03-28</th>\n",
       "      <td>17.0324</td>\n",
       "      <td>16.6849</td>\n",
       "      <td>17.2864</td>\n",
       "      <td>18.3281</td>\n",
       "      <td>19.3032</td>\n",
       "      <td>19.8332</td>\n",
       "      <td>20.1371</td>\n",
       "      <td>20.3808</td>\n",
       "      <td>20.8210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-03-31</th>\n",
       "      <td>17.6639</td>\n",
       "      <td>17.6087</td>\n",
       "      <td>17.6879</td>\n",
       "      <td>18.5689</td>\n",
       "      <td>19.4285</td>\n",
       "      <td>20.0430</td>\n",
       "      <td>19.9823</td>\n",
       "      <td>20.4448</td>\n",
       "      <td>20.8994</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               V2TX     V6I1     V6I2     V6I3     V6I4     V6I5     V6I6  \\\n",
       "Date                                                                        \n",
       "2014-03-25  18.2637  18.2303  18.3078  19.0371  19.8378  20.3065  18.1063   \n",
       "2014-03-26  17.5869  17.4810  17.7009  18.4499  19.4150  19.9961  20.2562   \n",
       "2014-03-27  17.6397  17.5032  17.7608  18.6249  19.4860  20.0477  20.1078   \n",
       "2014-03-28  17.0324  16.6849  17.2864  18.3281  19.3032  19.8332  20.1371   \n",
       "2014-03-31  17.6639  17.6087  17.6879  18.5689  19.4285  20.0430  19.9823   \n",
       "\n",
       "               V6I7     V6I8  \n",
       "Date                          \n",
       "2014-03-25  20.8292  21.2046  \n",
       "2014-03-26  20.4541  20.8563  \n",
       "2014-03-27  20.4865  20.9449  \n",
       "2014-03-28  20.3808  20.8210  \n",
       "2014-03-31  20.4448  20.8994  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vstoxx_index.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 504 entries, 0 to 503\n",
      "Data columns (total 5 columns):\n",
      "DATE         504 non-null datetime64[ns]\n",
      "EXP_YEAR     504 non-null int64\n",
      "EXP_MONTH    504 non-null int64\n",
      "PRICE        504 non-null float64\n",
      "MATURITY     504 non-null datetime64[ns]\n",
      "dtypes: datetime64[ns](2), float64(1), int64(2)\n",
      "memory usage: 23.6 KB\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DATE</th>\n",
       "      <th>EXP_YEAR</th>\n",
       "      <th>EXP_MONTH</th>\n",
       "      <th>PRICE</th>\n",
       "      <th>MATURITY</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>499</th>\n",
       "      <td>2014-03-31</td>\n",
       "      <td>2014</td>\n",
       "      <td>7</td>\n",
       "      <td>20.40</td>\n",
       "      <td>2014-07-18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>500</th>\n",
       "      <td>2014-03-31</td>\n",
       "      <td>2014</td>\n",
       "      <td>8</td>\n",
       "      <td>20.70</td>\n",
       "      <td>2014-08-15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>501</th>\n",
       "      <td>2014-03-31</td>\n",
       "      <td>2014</td>\n",
       "      <td>9</td>\n",
       "      <td>20.95</td>\n",
       "      <td>2014-09-19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>502</th>\n",
       "      <td>2014-03-31</td>\n",
       "      <td>2014</td>\n",
       "      <td>10</td>\n",
       "      <td>21.05</td>\n",
       "      <td>2014-10-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>503</th>\n",
       "      <td>2014-03-31</td>\n",
       "      <td>2014</td>\n",
       "      <td>11</td>\n",
       "      <td>21.25</td>\n",
       "      <td>2014-11-21</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          DATE  EXP_YEAR  EXP_MONTH  PRICE   MATURITY\n",
       "499 2014-03-31      2014          7  20.40 2014-07-18\n",
       "500 2014-03-31      2014          8  20.70 2014-08-15\n",
       "501 2014-03-31      2014          9  20.95 2014-09-19\n",
       "502 2014-03-31      2014         10  21.05 2014-10-17\n",
       "503 2014-03-31      2014         11  21.25 2014-11-21"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vstoxx_futures.info()\n",
    "\n",
    "vstoxx_futures.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 46960 entries, 0 to 46959\n",
      "Data columns (total 7 columns):\n",
      "DATE         46960 non-null datetime64[ns]\n",
      "EXP_YEAR     46960 non-null int64\n",
      "EXP_MONTH    46960 non-null int64\n",
      "TYPE         46960 non-null object\n",
      "STRIKE       46960 non-null float64\n",
      "PRICE        46960 non-null float64\n",
      "MATURITY     46960 non-null datetime64[ns]\n",
      "dtypes: datetime64[ns](2), float64(2), int64(2), object(1)\n",
      "memory usage: 2.9+ MB\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DATE</th>\n",
       "      <th>EXP_YEAR</th>\n",
       "      <th>EXP_MONTH</th>\n",
       "      <th>TYPE</th>\n",
       "      <th>STRIKE</th>\n",
       "      <th>PRICE</th>\n",
       "      <th>MATURITY</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>46955</th>\n",
       "      <td>2014-03-31</td>\n",
       "      <td>2014</td>\n",
       "      <td>11</td>\n",
       "      <td>P</td>\n",
       "      <td>85.0</td>\n",
       "      <td>63.65</td>\n",
       "      <td>2014-11-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46956</th>\n",
       "      <td>2014-03-31</td>\n",
       "      <td>2014</td>\n",
       "      <td>11</td>\n",
       "      <td>P</td>\n",
       "      <td>90.0</td>\n",
       "      <td>68.65</td>\n",
       "      <td>2014-11-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46957</th>\n",
       "      <td>2014-03-31</td>\n",
       "      <td>2014</td>\n",
       "      <td>11</td>\n",
       "      <td>P</td>\n",
       "      <td>95.0</td>\n",
       "      <td>73.65</td>\n",
       "      <td>2014-11-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46958</th>\n",
       "      <td>2014-03-31</td>\n",
       "      <td>2014</td>\n",
       "      <td>11</td>\n",
       "      <td>P</td>\n",
       "      <td>100.0</td>\n",
       "      <td>78.65</td>\n",
       "      <td>2014-11-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46959</th>\n",
       "      <td>2014-03-31</td>\n",
       "      <td>2014</td>\n",
       "      <td>11</td>\n",
       "      <td>P</td>\n",
       "      <td>105.0</td>\n",
       "      <td>83.65</td>\n",
       "      <td>2014-11-21</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            DATE  EXP_YEAR  EXP_MONTH TYPE  STRIKE  PRICE   MATURITY\n",
       "46955 2014-03-31      2014         11    P    85.0  63.65 2014-11-21\n",
       "46956 2014-03-31      2014         11    P    90.0  68.65 2014-11-21\n",
       "46957 2014-03-31      2014         11    P    95.0  73.65 2014-11-21\n",
       "46958 2014-03-31      2014         11    P   100.0  78.65 2014-11-21\n",
       "46959 2014-03-31      2014         11    P   105.0  83.65 2014-11-21"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vstoxx_options.info()\n",
    "\n",
    "vstoxx_options.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[Timestamp('2014-01-17 00:00:00'),\n",
       " Timestamp('2014-02-21 00:00:00'),\n",
       " Timestamp('2014-03-21 00:00:00'),\n",
       " Timestamp('2014-04-18 00:00:00'),\n",
       " Timestamp('2014-05-16 00:00:00'),\n",
       " Timestamp('2014-06-20 00:00:00'),\n",
       " Timestamp('2014-07-18 00:00:00'),\n",
       " Timestamp('2014-08-15 00:00:00'),\n",
       " Timestamp('2014-09-19 00:00:00'),\n",
       " Timestamp('2014-10-17 00:00:00'),\n",
       " Timestamp('2014-11-21 00:00:00')]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "third_fridays = sorted(set(vstoxx_futures['MATURITY']))\n",
    "third_fridays"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Modeling the VSTOXX Options"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Calibration of the VSTOXX Model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Conclusions"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Python Scripts"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### dx_srd_calibration.py"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"http://hilpisch.com/tpq_logo.png\" alt=\"The Python Quants\" width=\"35%\" align=\"right\" border=\"0\"><br>\n",
    "\n",
    "<a href=\"http://tpq.io\" target=\"_blank\">http://tpq.io</a> | <a href=\"http://twitter.com/dyjh\" target=\"_blank\">@dyjh</a> | <a href=\"mailto:team@tpq.io\">team@tpq.io</a>\n",
    "\n",
    "**DX Analytics** |\n",
    "<a href=\"http://dx-analytics.com\">http://dx-analytics.com</a>\n",
    "\n",
    "**Quant Platform** |\n",
    "<a href=\"http://quant-platform.com\">http://quant-platform.com</a>\n",
    "\n",
    "**Python for Finance Books** |\n",
    "<a href=\"http://books.tpq.io\" target=\"_blank\">http://books.tpq.io</a>\n",
    "\n",
    "**Python for Finance Training** |\n",
    "<a href=\"http://training.tpq.io\" target=\"_blank\">http://training.tpq.io</a>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [Root]",
   "language": "python",
   "name": "Python [Root]"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
